#ifndef VC_H
#define VC_H

#include <stdio.h>
#include <stdlib.h>
#include "engine.h"
#include "main.h"
#include "keyboard.h"
#include "vc.h"

// Single-byte opcode descriptors

#define EXEC 1
#define VAR0_ASSIGN 2
#define VAR1_ASSIGN 3
#define VAR2_ASSIGN 4
#define GENERAL_IF 5
#define ELSE 6
#define GOTO 7
#define FOR_LOOP0 8
#define FOR_LOOP1 9
#define SWITCH 10
#define CASE 11
#define ENDSCRIPT 255

// Single-byte operand descriptors

#define OP_IMMEDIATE 1
#define OP_VAR0 2
#define OP_VAR1 3
#define OP_VAR2 4
#define OP_GROUP 5

// Single-byte IF handler parameters

#define ZERO 0
#define NONZERO 1
#define EQUALTO 2
#define NOTEQUAL 3
#define GREATERTHAN 4
#define GREATERTHANOREQUAL 5
#define LESSTHAN 6
#define LESSTHANOREQUAL 7

// Single byte assignment descriptors

#define SET 1
#define INCREMENT 2
#define DECREMENT 3
#define INCSET 4
#define DECSET 5

// Operand combination descriptors
#define ADD 1
#define SUB 2
#define MULT 3
#define DIV 4
#define MOD 5
#define OP_END 255

extern unsigned char* magicvc;

// MAP VC code buffer
extern unsigned char* mapvc;

// Effect VC code buffer
extern unsigned char* effectvc;

// Startup.vcs
extern unsigned char* startupvc;

// The data buffer for VC use
extern unsigned char* vcdatabuf;

// current code data ptr
extern unsigned char* code;

extern unsigned char* basevc;

// Map script offset table
extern unsigned int scriptofstbl[1024];

// Effect script offset table
extern unsigned int effectofstbl[1024];

// Magic script offset table - ric: 08/May/98 - who forgot this then?
extern unsigned int magicofstbl[1024];

// Startup script offset table
extern unsigned int startupofstbl[1024];

// Number of scripts in current map VC
extern int numscripts;

// Chain/call pass variables
extern unsigned int varl[10];

// Temporary/Throwaway variables
extern unsigned int tvar[26];

// abort VC loop;
extern char killvc;

extern void InitVCMem(int mapvcm);
extern void LoadVC(FILE* f);
extern unsigned char GrabC();
extern unsigned short GrabW();
extern unsigned int GrabD();
extern void GrabString(char* str);
extern void ProcessVar0Assign();
extern void ProcessVar1Assign();
extern void ProcessVar2Assign();
extern unsigned int ResolveOperand();
extern int ProcessOperand();
extern void ProcessIf();
extern void ProcessFor0();
extern void ProcessFor1();
extern void ProcessSwitch();
extern void ExecuteScript(unsigned short s);
extern void ExecuteHookedScript(unsigned short s);
extern void ExecuteMagicEffect(unsigned short s);
extern void ExecuteEffect(unsigned short s);
extern void ExecuteBlock();
extern void StartupScript();

#endif
